package plugin

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

type RemoteTemplate struct {
	Name  string            `json:"name"`
	Dirs  []string          `json:"dirs"`
	Files map[string]string `json:"files"`
}

func LoadRemoteTemplate(url string) error {
	resp, err := http.Get(url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	var rt RemoteTemplate
	if err := json.Unmarshal(body, &rt); err != nil {
		return err
	}

	RegisterTemplate(SimpleTemplate{
		templateName: "Remote: " + rt.Name,
		dirs:         rt.Dirs,
		files:        rt.Files,
	})

	fmt.Printf("✅ Loaded remote template: %s\n", rt.Name)
	return nil
}
